package org.dromara.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.dromara.bean.domain.HisDelivery;
import org.dromara.bean.service.IHisDeliveryService;
import org.dromara.common.core.domain.R;
import org.dromara.system.service.ISysHisDeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * Description: 物流公司
 *
 * @author Handy
 * Date: 2024/4/7
 */
@Slf4j
@Service
public class SysHisDeliveryServiceImpl implements ISysHisDeliveryService {
    @Autowired
    private IHisDeliveryService hisDeliveryService;

    @Override
    public R<?> listByDvyName(String dvyName) {
        List<HisDelivery> list = hisDeliveryService.listByDvyName(dvyName);
        return R.ok(list);
    }

    @Override
    public R<?> allList() {
        List<HisDelivery> list = hisDeliveryService.list();
        return R.ok(list);
    }

    @Override
    public R<?> queryPageList(HisDelivery hisDelivery, Integer pageNo, Integer pageSize, HttpServletRequest req) {
        Map<String, String[]> parameterMap = new HashMap<>();

//        for (String key : req.getParameterMap().keySet()) {
//            if ("column".equals(key)) {
//                parameterMap.put("column", new String[]{"rec_time"});
//            } else {
//                parameterMap.put(key, req.getParameterMap().get(key));
//            }
//        }
//
//        QueryWrapper<HisDelivery> queryWrapper = QueryGenerator.initQueryWrapper(hisDelivery, parameterMap);
//        Page<HisDelivery> page = new Page<HisDelivery>(pageNo, pageSize);
//        IPage<HisDelivery> pageList = hisDeliveryService.page(page, queryWrapper);
        return R.ok();
    }

    @Override
    public R<?> add(HisDelivery hisDelivery) {
        hisDelivery.setRecTime(new Date());
        hisDelivery.setModifyTime(new Date());
        hisDeliveryService.save(hisDelivery);
        return R.ok("添加成功！");
    }

    @Override
    public R<?> edit(HisDelivery hisDelivery) {
        hisDelivery.setModifyTime(new Date());
        hisDeliveryService.updateById(hisDelivery);
        return R.ok("编辑成功!");
    }

    @Override
    public R<?> delete(String id) {
        hisDeliveryService.removeById(id);
        return R.ok("删除成功!");
    }

    @Override
    public R<?> deleteBatch(String ids) {
        hisDeliveryService.removeByIds(Arrays.asList(ids.split(",")));
        return R.ok("批量删除成功！");
    }

    @Override
    public R<?> queryById(String id) {
        HisDelivery hisDelivery = hisDeliveryService.getById(id);
        return R.ok(hisDelivery);
    }
}
